package com.solo.jdbc;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.util.ArrayList;

@WebServlet(name = "UserServlet", value = "/UserServlet")
public class UserServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        // 汉字编码设置
        request.setCharacterEncoding("utf-8");
        ArrayList<User> userList = new ArrayList<User>();
        userList.add(new User("admin","264309"));
        userList.add(new User("user1","123456"));
        userList.add(new User("user2","123"));
        request.setAttribute("userList", userList);
        request.getRequestDispatcher("/user.jsp").forward(request, response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // 汉字编码设置
        request.setCharacterEncoding("utf-8");

        ArrayList<User> userList = new ArrayList<User>();

        userList.add(new User("admin","264309"));
        userList.add(new User("user1","123456"));
        userList.add(new User("user2","123"));

        request.setAttribute("userList", userList);

        request.getRequestDispatcher("/user.jsp").forward(request, response);
    }
}